#include<stdio.h>
#include<assert.h>


void InserSort(int* a, int n)
{
	for (int i = 0; i < n - 1; i++)
	{
		int end = i;
		int tmp = a[i + 1];
		while (end >= 0)
		{
			if (a[end] > tmp)
			{
				a[end + 1] = a[end];
				end--;
			}
			else
				break;
			a[end + 1] = tmp;
		}
	}
}


void ShellSort(int* a, int n)
{
	int gap = n;
	while (gap>1)
	{
		gap /= 2;
		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			int tmp = a[i + gap];
			{
				while (end >= 0)
				{
					if (a[end] > tmp)
					{
						a[end + gap] = a[end];
						end -= gap;
					}
					else
						break;
				}
				a[end + gap] = tmp;
			}

		}

	}
}




int main()
{
	int arr[] = { 1,2,3,5,6,98,7,5,6,4 };
	//InserSort(&arr, sizeof(arr) / sizeof(int));
	ShellSort(&arr, sizeof(arr) / sizeof(int));
	return 0;
}